import {Local} from "/@utils/StorageTools";

export interface Menu {
    name: string;
    showName: string;
    path: string;
    index: number;
    component: any;
    show?: boolean;
    meta: {
        title?: string;
        keepAlive: boolean
    },
    children?: Menu[];
}

// 用户菜单
export const user_menu : Menu[] = [
    {name: 'Home', showName: '首页', path: '/home', index: 1,show: true, component: () => import('/@/views/home/Index.vue'), meta: {title: '首页', keepAlive: true}},
];

// 管理员菜单 index从1000开始
export const admin_menu : Menu[] = [
    {
        name: 'Home',
        showName: '管理员首页',
        path: '/index',
        index:1000,
        show: true,
        component: () => import('/@/views/home/AdminIndex.vue'),
        meta: {keepAlive: true},
    },
];

// 工作人员菜单 index从2000开始
export const worker_menu : Menu[] = [
    {name: 'Home',showName: '主页',path: '/index',index:2001, show: true, component: () => import('/@/views/home/homepage.vue'), meta: {keepAlive: true}},
    // {name: 'Home',showName: '工作人员首页',path: '/index',index:2000,show: true,component: () => import('/@/views/home/StaffIndex.vue'), meta: {keepAlive: true}},
];

// 测试功能菜单 用于快速测试 发布时记得删除
export const test_menu : Menu[] = [
    {name: 'yoloModel',showName: 'Yolo检测模块',path: '/yolo_model',index:3000, show: true, component: () => import('/@/views/yolo_model/index.vue'), meta: {keepAlive: true}},
    {name: 'imageRecognition',showName: '图片识别模块',path: '/image_recognition',index:3001, show: true, component: () => import('/@/views/image_recognition/index.vue'), meta: {keepAlive: true}},
    {name: 'system_status',showName: '系统监控',path: '/system_status',index:3002, show: true, component: () => import('/@/views/system_status/index.vue'), meta: {keepAlive: true}},
    {name: 'news',showName: '行业新闻',path: '/news',index:3003, show: true, component: () => import('/@/views/news/index.vue'), meta: {keepAlive: true}},
    {name: 'forum',showName: '论坛',path: '/forum',index:3004, show: true, component: () => import('/@/views/forum/index.vue'), meta: {keepAlive: true}},
    {name: 'forum_search',showName: '论坛搜索',path: '/forumSearch',index:3005, show: false, component: () => import('/@/views/forum/search.vue'), meta: {keepAlive: true}},
    {name: 'topic_detail',showName: '主题详情',path: '/topicdetail',index:3005, show: false, component: () => import('/@/views/forum/topicDetail.vue'), meta: {keepAlive: true}},
    {name: 'newsDetail',showName: '新闻详情',path: '/news-detail/:id',index:3006, show: false, component: () => import('/@/views/news/news_detail.vue'), meta: {keepAlive: true}},
    {name: 'chatbot',showName: '智能问答',path: '/chatbot',index:3007, show: true, component: () => import('/@/views/chatbot/chatView.vue'), meta: {keepAlive: true}},
    {name: 'encyclopedia',showName: '百科',path: '/encyclopedia',index:3008, show: true, component: () => import('/@/views/encyclopedia/EncyclopediaPortal.vue'), meta: {keepAlive: true}},
    {name: 'SearchResults',showName: '搜索结果',path: '/search',index:3008,component: () => import('/@/views/encyclopedia/SearchResults.vue'), meta: {title: '搜索结果',keepAlive: true}},
    {name: 'EntryDetail',showName: '词条详情',path: '/entry/:id',index:3008,component: () => import('/@/views/encyclopedia/EntryDetail.vue'), meta: {title: '词条详情',keepAlive: true}},
    {name: 'CategoryDetail',showName: '分类详情',path: '/category/:id',index:3008,component: () => import('/@/views/encyclopedia/CategoryDetail.vue'), meta: {title: '分类详情',keepAlive: true}},
];

// 最终返回的菜单
export const resultMenu: Menu[] = [];


export const getMenus = () => {
    // 先清空菜单
    resultMenu.splice(0,resultMenu.length);
    const userInfo = Local.get('userInfo')

    // 如果没有登录 返回空菜单
    if(userInfo === null){
        return resultMenu;
    }

    if (userInfo.userInfo.is_superuser) {
        resultMenu.push(...admin_menu)
        resultMenu.push(...test_menu)
        return resultMenu;
    }
    if(userInfo.userInfo.is_staff){
        resultMenu.push(...worker_menu)
        resultMenu.push(...test_menu)
        return resultMenu;
    }
    resultMenu.push(...user_menu);
    resultMenu.push(...test_menu)
    return resultMenu;
}
